package com.qfedu.stussm.controller;

import com.qfedu.stussm.entity.JwDept;
import com.qfedu.stussm.service.intf.JwDeptService;
import com.qfedu.stussm.vo.DeptR;
import com.qfedu.stussm.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JwDeptController {
    @Autowired
    private JwDeptService jwdeptService;

    @RequestMapping("api/stussm/jwinsert.do")
    public DeptR insert(JwDept jwDept) {
        System.out.println(jwDept);
        return jwdeptService.insert(jwDept);
    }


    @GetMapping("api/stussm/jwselect.do")
    public PageBeanVo select(String name, int page, int limit) {
        PageBeanVo select = jwdeptService.select(name, page, limit);
        //   System.out.println("controller:"+name);
        return select;
    }

    @GetMapping("api/stussm/jwdel.do")
    public DeptR del(Integer id) {
        System.out.println(id);
        return jwdeptService.del(id);
    }

    @PostMapping("api/stussm/jwupdate.do")
    public DeptR update(JwDept jwDept) {
        DeptR update = jwdeptService.update(jwDept);
        System.out.println(jwDept);
        return update;
    }

    @PostMapping("api/stussm/jwdelmany.do")
    public DeptR dele(Integer[] id) {
        System.out.println("ids:" + id);
        if (id == null) {
            return DeptR.fail();
        } else {
            for (Integer i : id) {
                System.out.println(i);
            }
            return jwdeptService.dele(id);
        }
    }
}
